/**
 * CRM收款计划
 * @author liuw
 * @date 2019/12/24
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        table,
        element,
        vueData = {

        },
        table_where = {

        },

    cols = [[
            {field: "GWCAORIU",width:100,title:"业务员",search:"default",searchOpts:{icon:true},hide:true}
            ,{field: "GWCAORIU_NAME",width:100,title:"业务员"}
            ,{field: "GWCAORIG",width:100,title:"所属部门",search:"default",searchOpts:{icon:true},hide:true}
            ,{field: "GWCAORIG_NAME",width:100,title:"所属部门"}
            ,{field: "GWCA006",width:100,title:"客户",sort:true,search:"default",searchOpts:{icon:true},hide:true}
            ,{field: "GWCA006_NAME",width:130,title:"客户",sort:true}
            ,{field: "GWCA005",width:100,title:"合同编号",sort:true,search:"default",searchOpts:{icon:true}}
            ,{field: "GWCA041",width:100,title:"合同金额"}
            ,{field: "GWCCSEQ",width:80,title:"序号",sort:true}
            ,{field: "GWCC001",width:100,title:"支付阶段",filterDatas: app.datas_("crm_gwci001_gwcc001"),
            search:"default",searchOpts:{type:'select'}}
            ,{field: "GWCC003",width:100,title:"收款比例"}
            ,{field: "XRCA009",width:100,title:"应收日期"}
            ,{field: "Amount_Received",width:100,title:"应收金额"}
            ,{field: "Actual_Amount_Received",width:100,title:"实际收款金额"}
            ,{field: "Actual_payment_date",width:100,title:"实际收款日期"}
            ,{field: "Amount_NotReceived",width:100,title:"未收金额"}
        ]],
        moduleName = '收款计划'
    ;

    var gwcq003 = app.Module.extend({
        init: function () {
            self = this;
            /* var _searchsArr = app.cloneJSON(cols[0]);*/
            self._super({
                _tag: 'gwcq003',
                _searchs: [{
                    id: 'gwcq003', tableId: 'gwcq003_table', datas: cols[0]
                }],
                _loadTplsFull: [
                    {dom: 'common_open_window', tpl: 'common/_open_window'}
                ]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwcq003_table'),
                    url: g_ctxPath + 'crm/gwcq003/getList',
                    title: moduleName + '表',
                    method: 'post',
                    id: 'gwcq003_table',
                    size: _layuiConfig.ui_size,
                    autoSort: false, //禁用前端自动排序
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter'],
                    height: 'full',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: table_where,
                    done: function (res, curr, count) {

                    }
                });
            });

            var tipsIndex = null;

            $(doc).on('click', function () {
                tipsIndex && layer.close(tipsIndex);
            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gwcq003_table', where: table_where});
        },

        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'gwcq003',
                    methods: {
                        handleIconClick: function (field) {
                            var vue = this;
                            if (field == 'GWCA005') { //合同
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'q_gwca005',
                                            columnList: [
                                                {label: '合同编号', prop: 'GWCA005', width: '150'},
                                                {label: '合同签订组织', prop: 'GWCAMLEGAL', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCA005 = data.GWCA005;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择合同编号',
                                        area: ['600px', '465px']
                                    }
                                });
                            } else if(field === 'GWCAORIU'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysuser_id',
                                            columnList: [
                                                {label: '账号', prop: 'ACCOUNT', width: '150'},
                                                {label: '姓名', prop: 'NAME', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCAORIU = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择业务员',
                                        area: ['600px', '470px']
                                    }
                                });
                            } else if(field === 'GWCAORIG'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysorg_id',
                                            columnList: [
                                                {label: '组织编号', prop: 'ID', width: '150'},
                                                {label: '组织名称', prop: 'NAME', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCAORIG = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择所属部门',
                                        area: ['600px', '470px']
                                    }
                                });
                            } else if(field === 'GWCA006'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_gwak001',
                                            columnList: [
                                                {label: '客户编号', prop: 'GWAK001', width: '150'},
                                                {label: '客户简称', prop: 'GWAKL003', width: '150'},
                                                {label: '客户繁称', prop: 'GWAKL004', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCA006 = data.GWAK001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择客户单位',
                                        area: ['600px', '470px']
                                    }
                                });
                            }
                        }
                    },
                    watch:{

                    },
                    created: function(){

                    }
                }]
            });

            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new gwcq003();

});
